package dao.impl;

import Util.MyBatisUtil;
import dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import pojo.User;

import java.util.List;

public class UserDaoimpl implements UserDao {
    @Override
    public List<User> findAll(String name, String pass, int offset, int pageSize) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).findAll(name,pass,offset,pageSize);
    }
    @Override
    public List<User> findAll2(User user, int offset, int pageSize) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).findAll2(user,offset,pageSize);
    }


    @Override
    public int addUser(User user) {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(UserDao.class).addUser(user);
         //提交事务
        session.commit();
        return result;
    }


    @Override
    public User findUserById(int id) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).findUserById(id);
    }



    @Override
    public int updateUser(User user) {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(UserDao.class).updateUser(user);
        //提交事务
        session.commit();
        return result;
    }
    @Override
    public int deleteUserById(int id) {
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(UserDao.class).deleteUserById(id);
        //提交事务
        session.commit();
        return result;
    }

    @Override
    public int count(User user) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).count(user);
    }
}
